<template>
  <view
    class="component-container"
    :style="{
      height: topOccludedAreaHeight + customHeaderHeight + 'px',
      paddingTop: topOccludedAreaHeight + 'px',
      backgroundColor: props.backgroundColor
    }"
  >
    <uni-icons type="back" size="20" class="back" @click="toBack" v-if="!props.hiddenBack"></uni-icons>
    <span class="title">
      {{ props.title }}
    </span>
  </view>
</template>

<script setup lang="ts">
import $store from '@/store'
import { ref, computed } from 'vue'
const { topOccludedAreaHeight, customHeaderHeight, completeSafeHeight } = $store.app.getSystemParam()
const props = defineProps({
  title: {
    type: String,
    default: ''
  },
  backgroundColor: {
    type: String,
    default: '#fff'
  },
  hiddenBack: {
    type: Boolean,
    default: false
  }
})
function toBack() {
  uni.navigateBack()
}
const customHeaderHeightAndUnit = computed(() => customHeaderHeight + 'px')
</script>

<style scoped lang="scss">
.component-container {
  $padding-size: 4%;

  position: fixed;
  top: 0;
  z-index: 1;
  display: flex;
  justify-content: space-between;
  align-items: center;
  padding: 0 $padding-size;
  width: 100vw;
  text-align: center;
  box-sizing: border-box;

  .center-block {
    position: absolute;
    top: 0;
    left: 0;
  }

  .back {
    z-index: 1001;
  }

  .title {
    position: absolute;
    bottom: 0;
    z-index: 1000;
    display: block;
    width: 100% - $padding-size * 2;
    height: v-bind(customHeaderHeightAndUnit);
    text-align: center;
    line-height: v-bind(customHeaderHeightAndUnit);
  }
}
</style>
